import time

from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser


class RegisterPage(Base):
    register_url = 'http://139.129.26.163/user.php?act=register'

    # 用户名
    def input_username(self, username):
        self.send_keys((By.ID, 'username'), username)

    # 邮箱
    def input_email(self, email):
        self.send_keys((By.ID, 'email'), email)

    # 密码
    def input_password(self, password):
        self.send_keys((By.ID, 'password1'), password)

    # 确认密码
    def confirm_password(self, password):
        self.send_keys((By.ID, 'conform_password'), password)

    # qq
    def input_qq(self, qq=''):
        self.send_keys((By.NAME, 'extend_field2'), qq)

    # 办公电话
    def input_office_phone(self, office_phone=''):
        self.send_keys((By.NAME, 'extend_field3'), office_phone)

    # 家庭电话
    def input_family_phone(self, family_phone=''):
        self.send_keys((By.NAME, 'extend_field4'), family_phone)

    # 手机
    def input_mobile_phone(self, mobile_phone):
        self.send_keys((By.NAME, 'extend_field5'), mobile_phone)

    # 密码提示问题
    def select_password_prompt(self, index=0):
        self.select_by_index((By.NAME, 'sel_question'), index)

    # 密码提示答案
    def input_password_prompt_answer(self, answer=''):
        self.send_keys((By.NAME, 'passwd_answer'), answer)

    # 协议确定按钮
    def agreement_confirm(self):
        self.click((By.NAME, 'agreement'))

    # 注册按钮
    def register_button(self):
        self.click((By.NAME, 'Submit'))


if __name__ == '__main__':
    browser = open_browser()
    r = RegisterPage(browser)
    r.get(r.register_url)
    r.input_username('w12345')
    time.sleep(2)
    r.input_email('77307929@qq.com')
    time.sleep(2)
    r.input_password('wl1236')
    time.sleep(2)
    r.confirm_password('wl1236')
    time.sleep(2)
    r.input_qq()
    time.sleep(2)
    r.input_office_phone('13251803065')
    time.sleep(2)
    r.input_family_phone('13251230256')
    time.sleep(2)
    r.input_mobile_phone('1575451515')
    time.sleep(2)
    r.select_password_prompt()
    time.sleep(2)
    r.input_password_prompt_answer()
    time.sleep(2)
    r.register_button()
    time.sleep(5)
    r.quit()
